<SCRIPT language="JavaScript" type=text/javascript>
/*
 * Ext JS Library 2.0
 * Copyright(c) 2006-2007, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */
 
var viewport;
var boxComponent;
Ext.BLANK_IMAGE_URL = 'ext-2.0/resources/images/default/s.gif';

Ext.onReady(function(){
	Ext.QuickTips.init();
	
	/*
	 * Create tools for windows
	 */	
    var viewCalls = [{
        id:'search',
		title: 'View Contacts',
        handler: function(){
            window.location = 'contactForm.php?tab=1';
        }
    
    }];
	var viewMessages = [{
        id:'search',
        handler: function(){
            window.location = 'messages.php';
        }
    
    }];
	var viewCalendar = [{
        id:'search',
        handler: function(){
            window.location = 'calendar.php';
        }
    
    }];
    var viewReports = [{
        id:'search',
        handler: function(){
            window.location = 'reports.php';
        }
    
    }];
	var viewResources = [{
        id:'search',
        handler: function(){
            Ext.Msg.alert('Message', 'You want to view the resource database.');
        }
    
    }];
	var viewLibrary = [{
        id:'search',
        handler: function(){
            window.location = 'library.php?tab=2';
        }
    
    }];	
	
	/*
	 * Create data source, column model and grid for dashboard 
	 * paging contacts grid.
	 */
	
	// Create the data source
	var contactStore = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy({
			url: 'ajaxDirector.php?handler=getContactsForGrid&viewPort=window'
	    }),			
	    reader: new Ext.data.JsonReader({
	        root: 'Contacts',
	        id: 'ContactID',
			totalProperty: 'TotalRows'
	    }, [
		{name: 'IDNumber', mapping: 'IDNumber'},
	    {name: 'SubjectLine', mapping: 'SubjectDiv'},
		{name: 'DateofContact', mapping: 'DateofContact'},
	    {name: 'Status', mapping: 'StatusDiv'}
	    ])		
	});	
	
	// Set up the column model
	var colModel = new Ext.grid.ColumnModel([{
           header: 'ID #',
           dataIndex: 'IDNumber',
		   width: 50,
		   menuDisabled: true
		},{
           header: "Subject",
           dataIndex: 'SubjectLine',
		   width: 200,
		   menuDisabled: true
        },{
           header: 'Date Entered',
           dataIndex: 'DateofContact',
		   menuDisabled: true
        },{
           header: 'Status',
           dataIndex: 'Status',
		   width: 50,
		   menuDisabled: true
        }]);

    // by default columns are sortable
    colModel.defaultSortable = true;
	
	// Set up grid
	var contactGrid = new Ext.grid.GridPanel({
        store: contactStore,
        cm: colModel,
		loadMask: true,
		stripeRows: true,		
		viewConfig: {
			forceFit:true
		},	
        bbar: new Ext.PagingToolbar({
            pageSize: 20,
            store: contactStore,
            displayInfo: true,
            displayMsg: 'Displaying contacts {0} - {1} of {2}',
            emptyMsg: "No contacts to display"            
        })
    });

    // trigger the data store load
    contactStore.load({params:{start:0, limit:20}});
    
    /*
	 * Create library items out grid
	 */
	var libraryStore = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy({
			url: 'ajaxDirector.php?handler=getLibraryItemsOut'
	    }),			
	    reader: new Ext.data.JsonReader({
	        root: 'Items',
	        id: 'CheckedOutID',
			totalProperty: 'TotalRows'
	    }, [
		{name: 'Title', mapping: 'Title'},
	    {name: 'BorrowerName', mapping: 'BorrowerName'},
		{name: 'DateLent', mapping: 'DateLent'},
	    {name: 'Status', mapping: 'Status'}
	    ])		
	});	
	
	// Set up the column model
	var libraryColModel = new Ext.grid.ColumnModel([{
           header: 'Title',
           dataIndex: 'Title',
		   width: 180,
		   menuDisabled: true
		},{
           header: 'Name',
           dataIndex: 'BorrowerName',
		   width: 100,
		   menuDisabled: true
        },{
           header: 'Date Out',
           dataIndex: 'DateLent',
		   menuDisabled: true
        },{
           header: 'Status',
           dataIndex: 'Status',
		   width: 50,
		   menuDisabled: true
        }]);

    // by default columns are sortable
    libraryColModel.defaultSortable = true;
	
	// Set up grid
	var libraryGrid = new Ext.grid.GridPanel({
        store: libraryStore,
        cm: libraryColModel,
		loadMask: true,
		stripeRows: true,		
		viewConfig: {
			forceFit:true
		},	
        bbar: new Ext.PagingToolbar({
            pageSize: 20,
            store: libraryStore,
            displayInfo: true,
            displayMsg: 'Displaying items {0} - {1} of {2}',
            emptyMsg: "No items to display"            
        })
    });
    
    libraryStore.load({params:{start:0, limit:20}});    
    
    viewport = new Ext.Viewport({
        layout:'border',
        items:[
			boxComponent = new Ext.BoxComponent({ 
                region: 'north',
                el:     'north',
                height: 55
            }),{
	            region:'west',
	            id:'west-panel',
	            title:'Toolbox',
	            split:true,
	            width: 200,
	            minSize: 175,
	            maxSize: 400,
	            collapsible: true,
	            margins:'0 0 5 5',
	            cmargins:'0 5 5 5',
	            layout:'accordion',
	            layoutConfig:{
	                animate:true
	            },
		            items: [{
		                title:'Main Menu',
		                autoScroll:true,
		                border:false,
		                iconCls:'iconNav',
						autoLoad: {url:"includes/menuMain.php", scripts:true}
		            },{
		                title:'Settings',
		                border:false,
		                autoScroll:true,
		                iconCls:'iconSettings',
						autoLoad: {url:"includes/dashboard/windowSettings.php", scripts:true}
		            },{
		                title:'Exports &amp; Downloads',
		                border:false,
		                autoScroll:true,
		                iconCls:'iconDownload',
						autoLoad: {url:"includes/dashboard/windowDownload.php?config=sidebar", scripts:true}
		            }]
	        },{
	            xtype:'portal',
	            region:'center',
	            id: 'center-panel',
	            margins:'0 5 5 0',
	            items:[{
	                columnWidth:.49,
	                style:'padding:10px 0 10px 10px',
	                items:[{
	                	/*
	                	 * This is where we will grab our panel position from the
	                	 * database for col 0 in order of pos
	                	 */
	                    title: 'Recent contacts',
						iconCls:'iconCalls',
						id: 'panelCalls',
	                    layout:'fit',
						height: 330,
						autoScroll:true,
	                    tools: viewCalls,
						items: contactGrid
					},{
	                    title: 'Calendar',
						iconCls:'iconCalendar',
						id: 'panelCalendar',
						height: 330,
	                    tools: viewCalendar,
	                    autoLoad: {url:"includes/dashboard/windowCalendar.php", scripts:true}						
	                },{
	                    title: 'Library',
						iconCls:'iconLibrary',
						id: 'panelLibrary',
	                    layout:'fit',
						height: 330,
						autoScroll:true,
	                    tools: viewLibrary,
						items: libraryGrid
	                }]
	            },{
	                columnWidth:.49,
	                style:'padding:10px 0 10px 10px',
	                items:[{
	                	/*
	                	 * This is where we will grab our panel position from the
	                	 * database for col 1 in order of pos
	                	 */
	                	id:         'panelMessages',
						iconCls:    'iconMessages',
	                    title:      'Messages',
						height:     330,
						autoScroll: true,
	                    tools:      viewMessages,
	                    autoLoad: {url:"includes/dashboard/windowMessages.php", scripts:true},
	                    tbar:[{
	                        tooltip:'Create new message',
	                        text: 'New Message',
	                        iconCls:'toolbarNewMessage',
							handler : function(){
				                messageSupportObj.openNewMessageForm();
				            }
	                    }]	                               
	                },{	                	
	                	title:   'Reports',
						id:      'panelReports',
						iconCls: 'iconReports',
						height:  330,
	                    tools:   viewReports,
	                    autoScroll:true,
	                    autoLoad: {url:"includes/dashboard/windowReports.php", scripts:true},
	                    tbar:[{
	                    	text:'Select report',
	                        iconCls:'toolbarEdit',
							menu:{
				                id:'menuReport',
				                cls:'reading-menu',
				                width:300,
				                items: [{
				                    text:'Contact Status',
				                    group:'rp-group',
				                    handler : function() {
				                    	reportGetDataObj.getReportData('contactStatus','reportWindowRenderDiv');
				                    },
				                    scope:this,
				                    iconCls:'iconBulletRed'
				                },{
				                    text:'Number of calls opened/closed by staff',
				                    group:'rp-group',
				                    handler : function() {
				                    	reportGetDataObj.getReportData('callsByStaffMember','reportWindowRenderDiv');
				                    },
				                    scope:this,
				                    iconCls:'iconBulletRed'
				                },{
				                    text:'Number of calls opened/closed by date',
				                    group:'rp-group',
				                    checkHandler : function() {
				                    	alert('Report 3');
				                    },
				                    scope:this,
				                    iconCls:'iconBulletRed'
				                },{
				                    text:'Number of calls by disability',
				                    group:'rp-group',
				                    checkHandler : function() {
				                    	alert('Report 3');
				                    },
				                    scope:this,
				                    iconCls:'iconBulletRed'
				                },{
				                    text:'Average time before contact is closed',
				                    group:'rp-group',
				                    checkHandler : function() {
				                    	alert('Report 3');
				                    },
				                    scope:this,
				                    iconCls:'iconBulletRed'
				                }]
				            }
	                    }]
	                },{
	                    title: 'Search',
						id: 'panelSearch',
						iconCls:'iconSearch',
						autoLoad: {url:"includes/dashboard/windowSearch.php", scripts:true}
	                },{
	                    title: 'Resources',
						id: 'panelResources',
						iconCls:'iconResources',
	                    tools: viewResources,
	                    autoLoad: {url:"includes/dashboard/windowResources.php", scripts:true}
	                }]
	            }]
	        }]
	    });	    
	    
	    /*
	     * Get number of items in trash
	     */
	     trashRenderObj.getNumberItemsInTrash();
});

Ext.ux.Portlet = Ext.extend(Ext.Panel, {
    anchor: '100%',
    frame:true,
    collapsible:true,
    draggable:true,
    cls:'x-portlet'
});
Ext.reg('portlet', Ext.ux.Portlet);

Ext.ux.PortalColumn = Ext.extend(Ext.Container, {
    layout: 'anchor',
    autoEl: 'div',
    defaultType: 'portlet',
    cls:'x-portal-column'
});
Ext.reg('portalcolumn', Ext.ux.PortalColumn);
</script>
